package com.h3c.ptability.task;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.h3c.ptability.dto.eos.EosUserClientDTO;
import com.h3c.ptability.dto.eos.UserRoleDTO;
import com.h3c.ptability.entity.PtAllWorker;
import com.h3c.ptability.entity.PtDept;
import com.h3c.ptability.entity.PtUserDeptMonth;
import com.h3c.ptability.mapper.PtAllWorkerMapper;
import com.h3c.ptability.mapper.PtDeptMapper;
import com.h3c.ptability.mapper.PtUserDeptMonthMapper;
import com.h3c.ptability.service.EosAuthService;
import com.h3c.ptability.service.IPtRoleUserService;
import com.h3c.ptability.service.IPtUserDeptMonthService;
import com.h3c.ptability.utils.AppBusinessException;
import com.h3c.ptability.utils.BusiEnumDefine;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.xxl.job.core.log.XxlJobLogger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author :j262963
 * @date :2022/12/2 09:22
 * @description :将部门主管根据部门层级加入到对应的主管角色中(合同平台)
 */
@JobHandler(value = "resetDeptManagerRoleSignHandler")
@Component
@Slf4j
public class ResetDeptManagerRoleHandler extends IJobHandler {


    @Resource
    private PtDeptMapper ptDeptMapper;

    /**
     * EOS相关接口
     */
    @Resource
    private EosAuthService eosAuthService;

    @Resource
    private IPtRoleUserService ptRoleUserService;

    /**
     * 员工
     */
    @Resource
    private PtAllWorkerMapper ptAllWorkerMapper;

    private static String errMsg;

    public ResetDeptManagerRoleHandler() {
    }

    /**
     * 开启定时任务
     *
     * @param param 掺入参数
     * @return 返回执行结果
     * @throws Exception 异常信息
     */
    @Override
    public ReturnT<String> execute(String param) throws Exception {
        XxlJobLogger.log("XXL-JOB, resetDeptManagerRoleHandler.");
        XxlJobLogger.log("准备开始调用方法");
        ptRoleUserService.updateDeptManagerRole();
        XxlJobLogger.log("调用结束");
        return SUCCESS;
    }


}
